<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>4_运算符</title>
</head>
<body>
<script>
    console.log(6/2) //3
    console.log(3/2) //1.5 除法会直接得出结果，不会舍弃小数部分

    //如果比较运算符左右两边任一一边有数字，会将字符串转换为数字再比较
    console.log(3>10) //false
    console.log(3>'10') //false
    console.log('3'>10) //false
    console.log('3'>'10') //true
    //如果比较运算符左右两边都是字符串比较字符串的编码值
    /*'博'.charCodeAt(0 查看'博'的值
    * '程晓宇.charCodeAt(2) 查看'宇'的值*/
    console.log('程晓宇'.charCodeAt(2));
    console.log('博'.charCodeAt());

    console.log('***************************')
    //Number()将参数转换为数字，如果得不到数值类型的结果:会得到NaN((Not a Number)
    console.log(Number('3'),typeof Number('3'));//3
    console.log(Number(true),typeof Number(true));//1
    console.log(Number(false),typeof Number(false));//0
    console.log(Number('你好'),typeof Number('你好'));//NaN

    let a = 1;
    let b = true;
    //疏散比较运算符,只比较值,Number(true)=1
    console.log(a==b);//true
    //严格比较运算符，先比较数据类型，在比较值 number != boolean
    console.log(a===b);//false

    //三元运算符
    let c = 0;
    console.log(c == 0 ? 'YES':'NO');//YSE
    //=是赋值符号，先给c赋值为0,Boolean(0)=false，所以取NO
    console.log(c = 0 ? 'YES':'NO')//NO
    console.log('++++++++++++++')
    //Boolean()将参数转为布尔类型的值
    //如果参数的值是0 空字符串 null undefined NaN 转为布尔都是false,其余都是true!
    console.log(Boolean(0));
    console.log(Boolean(null));
    console.log(Boolean(undefined));
    console.log(Boolean(NaN));
    console.log(Boolean(''));
    console.log(Boolean(' '));
    console.log(Boolean('马上下课了'));
</script>
</body>
</html>